<?php
include_once "../common.php";

if(isset($_GET['id']) && !empty($_GET['id']) && is_numeric($_GET['id']))
{
	// get website info...
	$query = "	SELECT 
					* 
				FROM Webshops 
				WHERE ID = '".str_replace("'","",$_GET['id'])."'
					AND CustomerID = '".str_replace("'","",$_SESSION['login']['ID'])."'";
	$result = $_MySQL->runQuery($query);
	if(mysql_num_rows($result) > 0)
	{
		$row = mysql_fetch_assoc($result);
		?>
		<table width="100%">
			<tr bgcolor="#0099FF">
				<td colspan="3">Verificatie <?=$row['URL'];?></td>
			</tr>
			<tr>
				<td colspan="2">&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td colspan="2" valign="top">
					<input type="radio" name="radio" id="radio" value="html" onclick="switchRadioButton(this);" />
					<label for="radio">Een HTML bestand uploaden</label>
				</td>
				<td valign="top" rowspan="2">
		        	<div style="display:none;" id="HTMLfile">
		        		<a href="downloadHTMLFILE.php?website=<?=$row['URL'];?>">Download file</a> <small>(klik om te downloaden)</small>
		        		<br />
		        		<br />Na het downloaden en opslaan op uw computer:
		        		<br />- Upload dit naar de root van je site via bijvoorbeeld een ftp client
		        		<br />- druk op valideren
		        		<br />
		        		<br /><input type="button" value=" Valideren " onclick="javascript:validateHTML();" />
		        	</div>
		        	<div style="display:none;" id="metaTag">
		        		<span id="metaFile"></span>
		        	</div>
		        </td>
			</tr>
			<tr>
		       	<td colspan="2" valign="top">
		       		<input type="radio" name="radio" id="radio2" value="meta" onclick="switchRadioButton(this);" />
		        	<label for="radio2">Metatag aan <?=$row['URL'];?> toevoegen</label>
		        </td>
			</tr>
		</table>
		<script>
		
			function switchRadioButton(element)
			{
				var value= $(element).val();
				$('#HTMLfile').toggle(false);
				$('#metaTag').toggle(false);
				if (value=='html')
				{
					$('#HTMLfile').toggle(true);
				}
				else if (value=='meta')
				{
					$('#metaTag').toggle(true);
					generateMETA();
				}
			}
		
			function generateMETA()
			{
				$('#metaFile').html('een ongenblik geduld, uw meta tag wordt aangemaakt');
				var url = 'factory/generateMETAtag.php?website=<?=$row['URL'];?>';
				$.get(url, function(data){ $('#metaFile').html(data);});
			}
	
			function validateHTML()
			{
				var url = 'factory/checkHTMLfile.php?website=<?=$row['URL'];?>';
				$.get(url, function(data){
					if(data == '')
					{
						// close popup
						$(".popup").dialog('destroy');
						// reload page
						window.location = window.location;
					}
					else
					{
						alert(data);
					}
				});
			}
	
			function validateMETA()
			{
				var url = 'factory/checkMETAtag.php?website=<?=$row['URL'];?>';
				$.get(url, function(data){
					if(data == 'succes')
					{
						// close popup
						$(".popup").dialog('destroy');
						// reload page
						window.location = window.location;
					}
					else
					{
						alert(data);
					}
				});
			}
			
		</script>
		<?PHP
	}
	else
	{
		?>
		<b>ERROR</b>:<br />
		Onbekende website
		<?php
	}
}
else
{
	?>
	ERROR
	<?php
}